﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace hpm
{
    public partial class frmPhongBan : DevExpress.XtraEditors.XtraForm
    {

        clsKhoa obj_khoa = new clsKhoa();
        clsPhongBan obj_phongban = new clsPhongBan();
        DataTable dtbKhoa = new DataTable();
        DataTable dtbPhongBan = new DataTable();

        public frmPhongBan()
        {
            InitializeComponent();
        }

        private void frmPhongBan_Load(object sender, EventArgs e)
        {
            Init_LstKhoa();
            Init_LstPhongBan();
        }

        private void Init_LstPhongBan()
        {
            //MessageBox.Show(cbDsKhoa.SelectedValue.ToString());
            //dtbPhongBan = obj_phongban.GetAll_PhongBan();
            grdPhongBan.DataSource = obj_phongban.Get_PhongBan(cbDsKhoa.SelectedValue.ToString()); ;
        }

        private void Init_LstKhoa()
        {
            dtbKhoa = obj_khoa.GetAll_Khoa();
            cbDsKhoa.DataSource = dtbKhoa;
            cbDsKhoa.DisplayMember = "TenKhoa";
            cbDsKhoa.ValueMember = "MaKhoa";

            
        }



        private void cbDsKhoa_SelectedIndexChanged(object sender, EventArgs e)
        {

            grdPhongBan.DataSource = obj_phongban.Get_PhongBan(cbDsKhoa.SelectedValue.ToString());

            //grvPhongBan.SetRowCellValue(grvPhongBan.FocusedRowHandle, grvPhongBan.FocusedColumn, "THUANBUI");
            
            //grvPhongBan.SetRowCellValue(grvPhongBan.FocusedRowHandle, "MaKhoa", cbDsKhoa.SelectedValue);
        }

        private void grvPhongBan_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            //grvPhongBan.SetRowCellValue(grvPhongBan.FocusedRowHandle, "MaKhoa", cbDsKhoa.SelectedValue);

        }

        private void btnThemMoi_Click(object sender, EventArgs e)
        {
            grvPhongBan.AddNewRow();
            grvPhongBan.SetRowCellValue(grvPhongBan.FocusedRowHandle, "MaKhoa", cbDsKhoa.SelectedValue);
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            obj_phongban.CapNhatPhongBan();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
    }
}